home *** CD-ROM | disk | FTP | other *** search
- Subject: Bug in FW_CStrings
- Sent: 7/23/96 5:31 PM
- Received: 7/23/96 5:41 PM
- From: Kirk Swenson, kswenson@keypress.com
- Reply-To: ODF Interest, ODF-Interest@CILabs.ORG
- To: OpenDoc Development Framework Discussion List, ODF-Interest@CILabs.
-
- There appears to be a bug in ODF's reference-counted string handling when
- assigning from bounded strings (e.g. FW_CString32) to unbounded ones (e.g.
- FW_CString). It took a while to isolate, and I haven't pinpointed it
- exactly, but the following code demonstrates it:
-
- void TestStrings();
- void SetString( FW_CString& dst, char c);
-
- void TestStrings()
- {
- FW_CString dynamicStr1;
- FW_CString dynamicStr2;
- Str31 tStr1, tStr2;
-
- // After SetString, dynamicStr1 should be all 1's.
- // Instead it is a partially corrupted list of 1's.
- SetString( dynamicStr1, '1');
- dynamicStr1.ExportPascal( tStr1);
-
- // After this SetString call, both dynamicStr1 and dynamicStr2
- // contain corrupted 2's, even though nothing should have
- // happened to dynamicStr1.
- SetString( dynamicStr2, '2');
- dynamicStr1.ExportPascal( tStr1);
- dynamicStr2.ExportPascal( tStr2);
- }
-
- // Sets the destination string via a temporary bounded string
- void SetString( FW_CString& dst, char c)
- {
- FW_CString32 staticStr;
-
- // Initialize the temporary string
- for( int i=0; i<30; ++i)
- staticStr += c;
-
- // The destination string is now equivalent to the temporary string.
- // In ODF's reference-counting scheme, dst and staticStr refer to
- // the same internal representation.
- dst = staticStr;
-
- // Resetting staticStr should break the connection between the
- // destination string and the temporary string such that the
- // destination string is not affected.
- staticStr = "";
- }
-
- The bug does not manifest itself if the temporary string is not reset.
- Resetting staticStr appears to decrement the reference count of the static
- representation, but doesn't re-allocate it dynamically, which means that
- FW_CString32's destructor has a chance to corrupt part of the buffer.
- Unfortunately, I can't point to particular lines of code that are at fault,
- but this should get you to the vicinity. I presume this is not the
- expected behavior?
-
- Kirk Swenson
- Senior Software Engineer
- Key Curriculum Press
- kswenson@keypress.com
-
-
-